package org.demo.spring.aop.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class Logger {

    @Pointcut("execution(* org.demo.spring.aop.service..*(..))")
    public void pointcutMethod(){

    }

    @Before("pointcutMethod()")
    public void before(){
        System.out.println("方法执行前。。。。");
    }
    @After("pointcutMethod()")
    public void after(){
        System.out.println("方法执行完，返回前。。。。");
    }

    @AfterReturning("pointcutMethod()")
    public void afterReturn(){
        System.out.println("方法执行完，正常返回后。。。。");
    }

    @AfterThrowing("pointcutMethod()")
    public void afterException(){
        System.out.println("方法执行完，异常返回后。。。。");
    }

    @Around("pointcutMethod()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("方法执行中，执行1。。。。");
        Object proceed = joinPoint.proceed();
        System.out.println("方法执行中，执行2。。。。打印结果："+proceed);
        System.out.println("方法执行中，执行2。。。。");
    }



}
